<template>
	<view class="main">
		<view class="items">
			<view class="item" @click="gotoDetail(item)" v-for="item in datas">
				<view class="left">
					<image class="cover" :src="item.cover"></image>
				</view>
				<view class="right">
					<view class="top">
						<view class="name">{{item.name}}</view>
						<view class="title">({{item.title}})</view>
					</view>
					<view class="tags">
						<view class="tag" v-for="it in item.tags.split(',')">{{it}}</view>
					</view>
				</view>
			</view>
		</view><!--items end-->
	</view>
</template>

<script>
	import {getList} from '@/api/doctor.js'
	export default {
		data() {
			return {
				page:1,
				limit:10,
				status:false,
				datas:[]
			}
		},
		onLoad() {
			this.getDataList();
		},
		onPullDownRefresh() {
			this.page = 1;
			this.getDataList();
		},
		onReachBottom: function() {
			this.getDataList();
		},
		methods: {
			gotoDetail(item){
				uni.navigateTo({
					url:'/pages/index/list/data?id='+item.id
				})
			},
			getDataList() {
				let that = this;
				
				let limit = that.limit;
				let page = that.page;
				let dataList = that.datas;
				if (that.status) return;
				getList({
					page: page,
					limit: limit
				}).then(res => {
					let datasNew = [];
					let len = res.data.count;
					datasNew = dataList.concat(res.data.list);
					that.page++;
					that.$set(that, 'datas', datasNew);
					that.status = limit > len;
					that.page = that.page;
				});
			}
		}
	}
</script>

<style lang="scss">
	page {
	  width: 100%;
	  height: 100%;
	  // background-color: white;
	}
	.main {
		display: flex;
		flex-direction: column;
		padding: 30rpx;
		padding-bottom: 0;  
		padding-bottom: constant(safe-area-inset-bottom);  
		padding-bottom: env(safe-area-inset-bottom); 
		.items{
			display: flex;
			flex-direction: column;
			padding-bottom: 30rpx;
			.item{
				display: flex;
				flex-direction: row;
				background-color: #FFFFFF;
				// box-shadow: 0px 3px 6px 2px rgba(0, 0, 0, 0.1);
				border-radius: 10rpx;
				border-bottom: 1rpx solid #f1f1f1;
				margin-top: 20rpx;
				padding: 30rpx 30rpx;
				
				.left{
					display: flex;
					flex-direction: row;
					.cover{
						width: 120rpx;
						height: 120rpx;
						border-radius: 60rpx;
					}
				}
				.right{
					margin-left: 15rpx;
					display: flex;
					flex-direction: column;
					flex:1;
					.top{
						display: flex;
						flex-direction: row;
						align-items: center;
						.name{
							font-weight: bold;
							font-size: 30rpx;
							color: black;
						}
						.title{
							font-size: 22rpx;
							color: brown;
							margin-left: 5rpx;
						}
					}
					.tags{
						margin-top: 30rpx;
						display: flex;
						flex-direction: row;
						flex-wrap: wrap;
						.tag{
							padding: 10rpx 15rpx;
							border-radius: 10rpx;
							color: saddlebrown;
							background-color: oldlace;
							font-size: 22rpx;
							margin-right: 15rpx;
							margin-bottom: 15rpx;
						}
					}
				}
			}//item
		}//end items
	}
</style>
